<template>
  <el-form ref="form" :rules="rules" :model="currentVideo" label-width="80px" class="demo-form">


      <el-form-item label="标题" prop="title">
        <el-input v-model="currentVideo.title" ></el-input>
      </el-form-item>

      <el-form-item label="视频" prop="video" >
        <media-uploader v-model="currentVideo.video"  accept="video" :max-size="51200" :width="540" :height="360"></media-uploader>
      </el-form-item>

    <el-form-item>
      <span style="float: right">
          <el-button type="primary" @click="save('form')">保存</el-button>
      <el-button @click="back">返回</el-button>
      </span>

    </el-form-item>
  </el-form>
</template>
<script>
import { mapGetters } from "vuex";
import MediaUploader from "@/components/media-uploader";
export default {
  props: {
    isClose: Boolean
  },
  created() {
    this.refresh();
  },
  mounted() {},
  computed: {
    ...mapGetters({
      currentVideo: "currentVideo"
    })
  },
  data() {
    return {
      rules: {
        title: [
          { required: true, message: "请输入标题", trigger: "blur" },
          {
            min: 3,
            max: 15,
            message: "长度在 3 到 15 个字符",
            trigger: "blur"
          }
        ],
        video: [{ required: true, message: "请上传视频", trigger: "blur" }]
      }
    };
  },
  methods: {
    save(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$store
            .dispatch("addOrUpdateVideoS", this.currentVideo)
            .then(ret => {
              this.$notify({
                title: "视频添加成功",
                type: "success"
              });
              this.back();
            });
        } else {
          return false;
        }
      });
    },
    back() {
      this.$emit("close");
    }
  },
  components: {
    MediaUploader
  }
};
</script>
<style>
</style>
